#define _CRT_SECURE_NO_WARNINGS 1
#include<math.h>
int nearestValidPoint(int x, int y, int** points, int pointsSize, int* pointsColSize)
{
	int i = 0;
	int sum = 0;
	int k = 0;
	for (i = 0;i < pointsSize;i++)
		if (points[i][0] == pointsColSize[0] || points[i][1] == pointsColSize[1])
		{
			sum = abs(points[i][0] - pointsColSize[0]) + abs(points[i][1] - pointsColSize[1]);
			k = i;
			break;
		}

	if (i == pointsSize)
		return -1;
	for (;i < pointsSize;i++)
	{
		if(points[i][0] == pointsColSize[0] || points[i][1] == pointsColSize[1])
		{
			if (abs(points[i][0] - pointsColSize[0]) + abs(points[i][1] - pointsColSize[1]) < sum)
			{
				sum = abs(points[i][0] - pointsColSize[0]) + abs(points[i][1] - pointsColSize[1]);
				k = i;
			}
			else if (abs(points[i][0] - pointsColSize[0]) + abs(points[i][1] - pointsColSize[1]) == sum)
				if (points[i][0] + points[i][1] < points[k][0] + points[k][1])
					k = i;
		}
	}
	return k;
}

int main()
{
	int arr1[2] = { 3,4 };
	int arr2[5][2] = { {1,2},{3,1},{2,4},{2,3},{4,4} };
	int k = nearestValidPoint()
	return 0;
}